<?php 
ob_start();
include_once('connection/connection.php');
include('header.php');
include('menu.php');
include('config.php');

//function call for removing blank space from an array
function blanck($var)
{
if($var!="")
{
    return $var;
}
}

//function call for convert id into name
function getName($colName,$id)
{
	$sqlgetName="select distinct ".$colName."_name from tbl_lookup_location where ".$colName."_id in(".$id.")";
	$querygetName=mysql_query($sqlgetName);
	while($rowgetName=mysql_fetch_row($querygetName))
	{
	$name=$name."-".$rowgetName[0];
	}

	$name=explode("-",$name);
	$name=array_filter($name, "blanck");
	return $name=implode($name,",");
}
$frm=$_SESSION['form_id'];
$district=$_SESSION['district'];
                if($frm==q1)
				{
				$table=tbl_dtls_q1_main;
				$no=1;
				}
				if($frm==q2)
				{
				$table=tbl_dtls_q2_main;
				$no=2;
				}
				if($frm==q3)
				{
				$table=tbl_dtls_q3_loc;
				$no=3;
				}
				if($frm == cr)
				{
				$table=tbl_dtls_critical;
				$no=" Critical";
				}
				//if($frm == ufw)
				//{
				//$table=tbl_dtls_ufw_main;
				//$no=5;
				//}
?>
<html xmlns="http://www.w3.org/1999/xhtml">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<title>View Q1</title>
<head>
<script language="javascript" type="text/javascript" >
function PrintContent()
{
var DocumentContainer = document.getElementById('habit');
var WindowObject = window.open("PrintWindow",width=750,height=650,top=50,left=50,toolbars='no',scrollbars='yes',status='no',resizable='yes');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
</head>
<body>
<div id="habit">
<div align="center">
<form action="" method="post" enctype="multipart/form-data">
	<table border="0" width="735" id="table1" cellspacing="1" cellpadding="1">
		<tr>
			<td width="800" height="30">
			<p align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#990000"> 
			Questionnaire&nbsp;<?php echo $no;?></font></td>
		</tr>
		<tr>
			<td width="800" height="30">
			<p align="center">
			<font face="Verdana" style="font-size: 8.5pt; font-weight: 700" color="#990000"> 
			List</font></td>
		</tr>
		
		<tr>
			<td>&nbsp;<font face="Verdana" style="font-size: 10pt" color="#990000">District Name: <label><font face="Verdana" style="font-size: 8.5pt">
				  <?php echo getName('district',$district);?>
				</font></label></font></td>
		</tr>
	<tr>
		<td>
			<table border="1" width="800" id="table4" cellspacing="1" cellpadding="1" bgcolor="#FDF9EE" style="border-collapse:collapse; border-color:#99CCCC;">
				
				<tr>
					<td align="center" width="7%" bgcolor="#F7E6B7" height="36">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">SI No. </font></td>
					<td align="center" width="19%" bgcolor="#F7E6B7" height="36">
						<font style="font-size: 8.5pt" face="Verdana" color="#990000">
						Block Name</font></td>
						<td align="center" width="23%" bgcolor="#F7E6B7"><font style="font-size: 8.5pt" face="Verdana" color="#990000">Panchayat Name</font></td>
						<td align="center" width="18%" rowspan="" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Village Name</font></td>
					    <td align="center" width="19%" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Scheme Type</font></td>
					    <td align="center" width="19%" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Scheme Name</font></td>
				    <td align="center" width="19%" bgcolor="#F7E6B7" height="36">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Form Id</font></td>
				    <td align="center" width="19%" bgcolor="#F7E6B7"><font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Date</font></td>
				</tr>	
				<?php
				$qr2="select * from $table where district_id='$district' order by id asc";
				$res2=mysql_query($qr2);
				$siNo=1;
				while($row2=mysql_fetch_array($res2))
				{
				?>
				<tr>
				<td  height="23" align="center"><label id="habit_name"><font face="Verdana" style="font-size: 8.5pt"><?php echo $siNo++;?></font></label></td>
				<td height="23" align="center"><label id="habit_code"><font face="Verdana" style="font-size: 8.5pt"><?php $id="$row2[block_id]"; echo wordwrap(getName('block',$id), 20, "\n", true);?></font></label></td>
			   	<td height="23" align="center"><label id="habit_code"><font face="Verdana" style="font-size: 8.5pt"><?php $id="$row2[panchayat_id]"; echo wordwrap(getName('panchayat',$id), 20, "\n", true);?></font></label></td>
			   	<td height="23" align="center" ><label id="type_habit"><font face="Verdana" style="font-size: 8.5pt"><?php $id="$row2[village_id]"; echo wordwrap(getName('village',$id), 20, "\n", true);?></font></label></td>
				
				<?php
				//echo $table;
				if($table == tbl_dtls_q1_main || $table == tbl_dtls_q3_loc)
				{
				$qrScheme="select type_scheme,name_scheme from tbl_dtls_q1_main where form_id='$row2[form_id]'";
				$resScheme=mysql_query($qrScheme);
				$rowScheme=mysql_fetch_array($resScheme);
				$scheme_Type=$rowScheme['type_scheme'];
				$scheme_Name=$rowScheme['name_scheme'];
				}
				if($table == tbl_dtls_q2_main)
				{
				$qrScheme="select scheme_name from tbl_dtls_q2_main where form_id='$row2[form_id]'";
				$resScheme=mysql_query($qrScheme);
				$rowScheme=mysql_fetch_array($resScheme);
				$scheme_Type="HP";
				$scheme_Name=$rowScheme['scheme_name'];
				}	
				if($table == tbl_dtls_critical)
				{
				$qrScheme="select scheme_type from tbl_dtls_critical where form_id='$row2[form_id]'";
				$resScheme=mysql_query($qrScheme);
				$rowScheme=mysql_fetch_array($resScheme);
				$scheme_Type=$rowScheme['scheme_type'];
				$scheme_Name="#";
				}	
				?>
				<td height="23" align="center"><label id="status_e_nt"><font face="Verdana" style="font-size: 8.5pt"><?php echo $scheme_Type;?></font></label></td>
				<td height="23" align="center"><label id="status_e_nt"><font face="Verdana" style="font-size: 8.5pt"><?php echo $scheme_Name;?></font></label></td>
				<td height="23" align="center"><label id="status_e_nt"><font face="Verdana" style="font-size: 8.5pt"><?php echo "$row2[form_id]";?></font></label></td>
				<td align="center"><label id="status_e_nt"><font face="Verdana" style="font-size: 8.5pt"><?php echo "$row2[date]";?></font></label></td>
				</tr>
			<?php } ?>
			</table></td>
	</tr>
	<tr><td><a href='' onClick='return PrintContent()'>Print this Report</a></td></tr>
</table>
</form>		
</div>
</div>
</body>
</html>